#include "server.h"
#include "common.h"

#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>

static WSADATA s_wsa;

void wsa_init() {
	int wsa_result;
	LOG_INFO("init winsock");
	// init the winsock
	wsa_result = WSAStartup(MAKEWORD(2,2), &s_wsa);
	if (wsa_result != 0) {
		LOG_ERROR("winsock init error");
		exit(-1);
	}
}
void wsa_destroy() {
	LOG_INFO("destroy winsock");
	WSACleanup();
}

void server_init(Server * ps) {
	LOG_INFO("init server");
}

void server_destroy(Server * ps) {
	LOG_INFO("destroy server");
}

/**
 * big loop waiting socket event 
 */
int server_loop(Server * ps) {
	WSABUF data_buf;
	WSAOVERLAPPED overlapped;
	struct addrinfo hints;
	struct addrinfo *local = NULL;
	int result;

	memset(&hints, 0, sizeof(hints));
	hints.ai_flags = AI_PASSIVE;
	hints.ai_family = AF_INET;
	hints.ai_socktype =  SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;

	result = getaddrinfo(NULL, NULL, &hints, &local);
	assert(result != 0);
	return 0;
}


